package com.museum.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.museum.entity.DO.RolePermission;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author Ruiwen
 * @since 2020-12-19
 */
@Repository
public interface RolePermissionMapper extends BaseMapper<RolePermission> {
    /**
     * 根据roleId去角色权限表查询菜单ID
     * @param roleId
     * @return
     */
    @Select("SELECT permission_id from role_permission WHERE role_id=#{roleId}")
    List<Integer> Permission_rolePermission(Integer roleId);

    /**
     * 根据角色ID查询出角色对应的权限ID
     * @param roleID
     * @return
     */
    @Select("SELECT permission_id from role_permission WHERE role_id=#{roleID}  ORDER BY role_permission.permission_id")
    List<String> selectPermissionIdsByRoleId(Integer roleID);

    /**
     * 根据角色ID查询出角色对应的权限ID
     * @param roleID
     * @return
     */
    @Select("SELECT role_permission.permission_id  from role_permission ,area_permission WHERE role_id=#{roleID} AND role_permission.permission_id=area_permission.permission_id  AND area_permission.`status`=0")
    List<String> selectPermissionIdsByRoleIdForUpdate(Integer roleID);

}
